Skip to content

feat: add flagtype package with common flag.Value implementations#13

Merged
mfridman merged 1 commit intomainfrom
mf/flagtype-package
Feb 18, 2026
Merged

feat: add flagtype package with common flag.Value implementations#13
mfridman merged 1 commit intomainfrom
mf/flagtype-package

Conversation

@mfridman
Copy link
Collaborator

@mfridman mfridman commented Feb 18, 2026

This PR adds a new flagtype package that provides ready-made flag.Value implementations for common types that the stdlib flag package doesn't cover.

The supported types are:

  • StringSlice (repeatable flags)
  • Enum (restricted value set)
  • StringMap (repeatable key=value pairs)
  • URL (parsed and validated)
  • Regexp (compiled pattern).

All types implement flag.Getter so they integrate with cli.GetFlag[T]. Storage is internal to each value -- no destination pointers needed.

f.Var(flagtype.StringSlice(), "tag", "add a tag (repeatable)")
f.Var(flagtype.Enum("json", "yaml", "table"), "format", "output format")

tags   := cli.GetFlag[[]string](s, "tag")
format := cli.GetFlag[string](s, "format")

Also includes a design doc at docs/design/001-flagtype-api.md covering the API decision and alternatives considered.

@mfridman mfridman force-pushed the mf/flagtype-package branch from 09acd79 to 1ec9e49 Compare February 18, 2026 12:55
@mfridman mfridman merged commit 97198be into main Feb 18, 2026
3 checks passed
@mfridman mfridman deleted the mf/flagtype-package branch February 18, 2026 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments